//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;

namespace OpenLS.Drawing
{
    internal class TintTransform : PercentTransform
    {
        public TintTransform()
        {
        }

        public TintTransform(double value) : base(value)
        {
        }

        protected override string XmlName
        {
            get { return "tint"; }
        }

        public override Color Apply(Color c)
        {
            return CalculateTint(c, Value/100d);
        }

        public static Color CalculateTint(Color color, double tint)
        {
            const double HlsMax = 1;
            HslColor hsl = color;
            double t = tint;
            if (t < 0)
                hsl.L = hsl.L*(1 + t);
            if (t > 0)
                hsl.L = hsl.L*(1.0 - t) + (HlsMax - HlsMax*(1.0 - t));
            return hsl;
        }
    }
}